
package com.wrox.begspring;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class CalculateSpring {
                          
public interface Operation {
	long operate(long op1, long op2);
	String getOpsName();
}
		
public class OpAdd implements Operation {
	public OpAdd() {
	}

	public String getOpsName() {
	return " plus ";
	}

	public long operate(long op1, long op2) {
		return op1 + op2;
	}
}

  private Operation ops;
//  private ResultWriter wtr;
  public void setOps(Operation ops) {
  this.ops = ops;
}
 public static void show(){
     System.out.println("it works");
 }

public static void main(String[] args) {
  ApplicationContext context =
  new ClassPathXmlApplicationContext("beans.xml");
  BeanFactory factory = (BeanFactory) context;
  CalculateSpring calc =(CalculateSpring) factory.getBean("opsbean");
  calc.execute(args);
}
public void execute(String [] args) {
  long op1 = Long.parseLong("3");
  long op2 = Long.parseLong("4");
  show();
  //wtr.showResult("The result of " + op1 + ops.getOpsName() + op2 + " is " + ops.operate(op1, op2) + "!");
}
}